import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_myshop/pages/index.dart';
import 'package:flutter_myshop/provide/applicaiton.dart';
import 'package:flutter_myshop/provide/category_goods_list.dart';
import 'package:flutter_myshop/provide/child_category.dart';
import 'package:flutter_myshop/provide/index.dart';
import 'package:flutter_myshop/provide/shoping_car.dart';
import 'package:flutter_myshop/router/application.dart';
import 'package:flutter_myshop/router/routes.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

import 'common/constant.dart';

void main() {
  //创建子目录
  var childCategory = new ChildCategoryProvider();
  //分类页面展示商品状态
  var categoryGoodListProvider = new CategoryGoodListProvider();
  //购物车状态
  var shopingCarProvider = new ShopingCarProvider();
  //index页面状态
  var currentIndexProvider = new CurrentIndexProvider();
  //创建Provider
  var providers = new Providers();

  providers..provide(Provider<ChildCategoryProvider>.value(childCategory));

  providers
    ..provide(
        Provider<CategoryGoodListProvider>.value(categoryGoodListProvider));

  providers..provide(Provider<ShopingCarProvider>.value(shopingCarProvider));

  providers..provide(Provider<CurrentIndexProvider>.value(currentIndexProvider));

  runApp(ProviderNode(
    child: MyApp(),
    providers: providers,
  ));
}

/*
 * APP入口类
 */
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //路由
    final router = Router();
    Routes.configureRoutes(router);
    Application.router = router;

    //状态
    ProviderApplication.categoryGoodListProvider = Provide.value<CategoryGoodListProvider>(context);
    ProviderApplication.childCategoryProvider = Provide.value<ChildCategoryProvider>(context);
    ProviderApplication.shopingCarProvider = Provide.value<ShopingCarProvider>(context);
    ProviderApplication.currentIndexProvider = Provide.value<CurrentIndexProvider>(context);

  
    return Container(
      child: MaterialApp(
        title: '购物江',
        theme: ThemeData(
            primaryColor: Colors.blue, backgroundColor: Colors.white10),
        home: IndexPage(),
      ),
    );
  }
}
